<template>
  <el-dialog title="请选择需要线上建品的商品" :visible.sync="dialogTableVisible" width="50%">
    <el-table ref="multipleTable" :data="gridData" @selection-change="handleSelectionChange">
      <el-table-column type="selection" align="center" width="50" />
      <el-table-column property="item1Desc" label="商品名称" min-width="150" />
      <el-table-column property="upcNbr" label="条码" min-width="150" />
      <el-table-column property="deptNbr" label="部门" min-width="80" />
      <el-table-column property="finelineNbr" label="细分类" align="center" min-width="90">
        <template v-slot="scope">
          <el-input v-model="scope.row.finelineNbr" />
        </template>
      </el-table-column>
    </el-table>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" size="mini" @click="batchAgree">确 定</el-button>
      <el-button size="mini" @click="toggleSelection()">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { approvalAddBuyer } from '@/api/reason/dataO2o'
export default {
  data() {
    return {
      gridData: [{
        date: '2016-05-02',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }, {
        date: '2016-05-04',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }, {
        date: '2016-05-01',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }, {
        date: '2016-05-03',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }],
      dialogTableVisible: false,
      form: {
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '',
        desc: ''
      },
      formLabelWidth: '120px',
      loading: false,
      ids: [],
      idsApproval: [],
      choiceIds: [],
      batchFlag: false
    }
  },
  methods: {
    // 列表多选框触发
    handleSelectionChange(val) {
      // this.choiceIds = []
      val.forEach(item => {
        // this.choiceIds.push(item)
        item.approvalFlagBuyer = 1
      })
    },
    batchAgree() {
      // const notChoiceIds = this.idsPopChoiceIds(this.choiceIds, this.ids)
      this.url = '/approvalO2oController/add'
      console.log('this.choiceIds----', JSON.parse(JSON.stringify(this.gridData)))
      approvalAddBuyer(this.url, JSON.parse(JSON.stringify(this.gridData)))
      // let temp = []
      // let temp_1 = {id:1}
      // let temp_2 = {id:1}
      // temp.push(temp_1)
      // temp.push(temp_2)
      // approvalAddBuyer(this.url, temp)

      // 线下接口，测完放开
      if (this.batchFlag) {
        this.$parent.batchAgreeCoi()
      } else {
        this.$parent.doAgreeCoi()
      }
      this.dialogTableVisible = false
    },
    toggleSelection(rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row)
        })
      } else {
        this.$refs.multipleTable.clearSelection()
      }
      this.dialogTableVisible = false
    }
  }
}
</script>
<style>
  .customWidth{
  width:40%;
  }
</style>
